home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Image / GIS / Parser / E00.php
PHP Script  |  2004-03-24  |  4KB  |  125 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: E00 Parser                                     |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id: E00.php,v 1.9 2004/01/05 16:21:39 ostborn Exp $
  17. //
  18.  
  19. require_once 'Image/GIS/LineSet.php';
  20. require_once 'Image/GIS/Parser.php';
  21.  
  22. /**
  23. * E00 Parser.
  24. *
  25. * @version  $Revision: 1.9 $
  26. * @since    Image_GIS 1.0.0
  27. */
  28. class Image_GIS_Parser_E00 extends Image_GIS_Parser {
  29.     /**
  30.     * Constructor.
  31.     *
  32.     * @param  boolean $cache
  33.     * @param  boolean $debug
  34.     * @access public
  35.     */
  36.     function Image_GIS_Parser_E00($cache, $debug) {
  37.         $this->Image_GIS_Parser($cache, $debug);
  38.     }
  39.  
  40.     /**
  41.     * Parses a data file.
  42.     *
  43.     * @param  string  $dataFile
  44.     * @param  mixed   $color
  45.     * @return mixed
  46.     * @access public
  47.     */
  48.     function parseFile($dataFile, $color) {
  49.         $lineSet = new Image_GIS_LineSet($color);
  50.  
  51.         if ($fp = @fopen($dataFile, 'r')) {
  52.             $numRecords = 0;
  53.             $ln         = 0;
  54.  
  55.             while(0 || $line = fgets($fp, 1024)) {
  56.                 $ln ++;
  57.  
  58.                 if ($numRecords == 0 && 
  59.                     preg_match("#^\s+([0-9]+)\s+([-0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)#", $line, $a)) {
  60.                     $numRecords = $a[7];
  61.  
  62.                     $pl['x'] = -1;
  63.                     $pl['y'] = -1;
  64.                 }
  65.  
  66.                 else if ($numRecords &&
  67.                          preg_match("#^[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) {
  68.                     if ($this->debug) {
  69.                         echo $a[0] . '<br />';
  70.                     }
  71.  
  72.                     if ($pl['x'] != -1 &&
  73.                         $pl['y'] != -1) {
  74.                         $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]);
  75.                     }
  76.  
  77.                     $numRecords--;
  78.  
  79.                     $lineSet->addLine($a[1], $a[2], $a[3], $a[4]);
  80.  
  81.                     $pl['x'] = $a[3];
  82.                     $pl['y'] = $a[4];
  83.  
  84.                     $numRecords--;
  85.                 }
  86.  
  87.                 else if ($numRecords &&
  88.                          preg_match("#^[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) {
  89.                     if ($pl['x'] != -1 &&
  90.                         $pl['y'] != -1) {
  91.                         $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]);
  92.  
  93.                         $pl['x'] = $a[1];
  94.                         $pl['y'] = $a[2];
  95.                     }
  96.  
  97.                     $numRecords--;
  98.                 }
  99.  
  100.                 else if ($ln > 2) {
  101.             if ($this->debug) {
  102.             printf(
  103.                    'Died at: %s<br />',
  104.                    $ln
  105.                    );
  106.             }
  107.  
  108.                     break;
  109.                 }
  110.  
  111.                 else if ($this->debug) {
  112.                     echo $line . '<br />';
  113.                 }
  114.             }
  115.  
  116.             @fclose($fp);
  117.  
  118.             return $lineSet;
  119.         }
  120.  
  121.         return false;
  122.     }
  123. }
  124. ?>
  125.